package Model;

import Entity.Branch;
import Manager.BranchManager;
import Manager.Manager;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author CONG
 */
public class BranchTableModel extends AbstractTableModel {

    private Manager manager;
    public BranchTableModel(Manager manager) {
        this.manager=manager;
    }

    @Override
    public int getRowCount() {
        return manager.getBranchManager().getSize();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Branch br = manager.getBranchManager().getBranch(rowIndex);
        switch (columnIndex) {
            case 0:
                return br.getBranchCode();
            case 1:
                return br.getName();
            case 2:
                return br.getAddress();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Name";
            case 2:
                return "Address";
            default:
                return null;
        }
    }

    public void getBranchList(ArrayList<Branch> br) {
        manager.getBranchManager().getBranchList(br);
    }

    public int getSize() {
        return manager.getBranchManager().getSize();
    }
    
    public Branch getBranch(int index){
        return manager.getBranchManager().getBranch(index);
    }
    public boolean addBranch(Branch br){
        return manager.getBranchManager().addBranch(br);
    }
    public boolean updateBranch(Branch br){
        return manager.getBranchManager().updateBranch(br);
    }
    public boolean removeBranch(Branch br){
        return manager.getBranchManager().deleteBranch(br);
    }
}
